#!/usr/bin/env python
# encoding: utf-8

from django import forms

from app01 import models
from app01.forms.bootstrap import BootStrapForm


class WikiModelForm(BootStrapForm, forms.ModelForm):
	class Meta:
		model = models.Wiki
		fields = [ 'title', 'content', 'product', 'report_date','shift', 'parent', 'DRI', 'DRI_Leader', 'deal_time', 'priority']

	def __init__(self, request, *args, **kwargs):
		super().__init__(*args, **kwargs)
		self.request = request
		# 获取站点列表
		# station_list=models.ProjectStation.objects.filter(project=request.tracer.project.id).values_list('id','station__name')
		# self.fields['Station'].choices =station_list
		# 获取产品列表
		product_list=models.Product.objects.filter(project=request.tracer.project.id).values_list('id','name')
		self.fields['product'].choices =product_list

		# 找到需要的字段把它绑定的数据重置
		# 数据 = 去数据库中获取当前项目首页的Wiki标题
		total_data_list = [("", "请选择")]
		data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id', 'title')
		total_data_list.extend(data_list)
		self.fields['parent'].choices = total_data_list
